package com.geor.gcv.core.ui;

import java.util.ArrayList;
import java.util.List;

import org.opencv.core.Mat;

import com.geor.gcv.core.mat.ProcessImage;
import com.geor.gcv.core.mat.ProcessImageDefalut;

/**
 * swing 窗口
 * 
 * @author geor.lusongnan
 *
 */
public class ImageWindow {
	private PanelObservable obserable = null;
	private ImagePanel panel = null;
	private ProcessImage process = null;
	private int width = 1900;
	private int height = 1000;
	private boolean flag = false;

	public ImageWindow() {
		process = new ProcessImageDefalut();
		obserable = new PanelObservable(process);
		panel = new ImagePanel("def", width, height, obserable);
	}

	public ImageWindow(String title) {
		process = new ProcessImageDefalut();
		obserable = new PanelObservable(process);
		panel = new ImagePanel(title, width, height, obserable);
	}

	public void clear() {
		panel.getImages().clear();
		panel.repaint();
	}

	/**
	 * 显示界面
	 */
	public void show() {
		if (!flag)
			panel.init();
		flag = true;
	}

	public void colse() {
		if (flag)
			panel.close();
		flag = false;
	}
	
	public void setTitle(String title) {
		panel.setTitle(title);
	}

	public void addImg(Mat img) {
		List<Mat> mats = new ArrayList<Mat>();
		mats.add(img);
		addImg(mats);
	}

	public void addImg(List<Mat> imgs) {
		if (flag) {
			try {
				obserable.setParams(imgs);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else
			throw new RuntimeException("面板没有显示!");
	}

	public void setObserable(PanelObservable obserable) {
		this.obserable = obserable;
	}

	public PanelObservable getObserable() {
		return obserable;
	}

	public void setPanel(ImagePanel panel) {
		this.panel = panel;
	}

	public ProcessImage getProcess() {
		return process;
	}

	public void setProcess(ProcessImage process) {
		this.process = process;
	}

	protected int getWidth() {
		return width;
	}

	protected void setWidth(int width) {
		this.width = width;
	}

	protected int getHeight() {
		return height;
	}

	protected void setHeight(int height) {
		this.height = height;
	}

	public boolean isFlag() {
		return flag;
	}

}
